package com.xunji.standard.common;

/**
 * Copyright (c) 2019
 * <p>
 * 类名:isn-server <br/>
 * 创建日期: 2019/2/26 下午4:56 <br/>
 * 修改日期: 2019/2/26 下午4:56 <br/>
 *
 * @author chenqi (创建人)
 * @version 1.0
 * @since
 */
public enum ResultCodeEnum implements ResultType {
    SUCCESS(0, "成功"),
    FAIL(1, "失败"),
    SERVER_ERROR(500, "服务异常"),
    INVALID_PARAM(10004, "无效参数"),
    DATA_EMPTY_ERROR(11002, "没有数据"),
    NODE_CAN_NOT_DELETE(40001, "当前节点不可删除"),
    LOGIN_NAME_NOT_EXIT(40002, "用户名不存在");

    private Integer code;

    private String message;

    ResultCodeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public static String getMessage(String name) {
        for (ResultCodeEnum item : ResultCodeEnum.values()) {
            if (item.name().equals(name)) {
                return item.message;
            }
        }
        return name;
    }

    public static Integer getCode(String name) {
        for (ResultCodeEnum item : ResultCodeEnum.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.name();
    }
}
